<?php
function __autoload($class_name) {
    require_once 'class/'.$class_name . '.php';
}

if(isset ($_POST['member_check']) && $_POST['member_email'] != '' ) {
   $member_obj = new Member();
   if($member_obj->member_exist(trim($_POST['member_email'])) != false) {
       echo 'available';
   }
}

if(isset ($_POST['submit_nl'])) {
        if($_POST['newsletter_email'] == '') {
            echo 'no-email';
        } else if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_POST['newsletter_email'])) {
            echo "invalid-email";
	} else {
            // grab an API Key from http://admin.mailchimp.com/account/api/
            $api = new MCAPI('81aea8da84e0ddc5b81dc519d45ac099-us4');

            // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
            // Click the "settings" link for the list - the Unique Id is at the bottom of that page.
            $list_id = "8b919076b6";

            if($api->listSubscribe($list_id, $_POST['newsletter_email'], '') === true) {
                    // It worked!
                    echo 'success';
            }else{
                    // An error ocurred, return error message
                    echo $api->errorMessage;
            }
        }
}

?>
